/*     */ package com.feeyin.radar.sys.dao.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.Page;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.dao.DepartmentDAO;
/*     */ import com.feeyin.radar.sys.dao.FunctionOperateDAO;
/*     */ import com.feeyin.radar.sys.dao.OperateDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.model.FunctionOperate;
/*     */ import com.feeyin.radar.sys.model.Operate;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.orm.ibatis.SqlMapClientTemplate;
/*     */ import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
/*     */ 
/*     */ public class UserDAOImpl extends SqlMapClientDaoSupport
/*     */   implements UserDAO
/*     */ {
/*     */   private DepartmentDAO departmentDAO;
/*     */   private OperateDAO operateDAO;
/*     */   private FunctionOperateDAO functionOperateDAO;
/*     */ 
/*     */   public DepartmentDAO getDepartmentDAO()
/*     */   {
/*  34 */     return this.departmentDAO;
/*     */   }
/*     */ 
/*     */   public void setDepartmentDAO(DepartmentDAO departmentDAO) {
/*  38 */     this.departmentDAO = departmentDAO;
/*     */   }
/*     */ 
/*     */   public OperateDAO getOperateDAO() {
/*  42 */     return this.operateDAO;
/*     */   }
/*     */ 
/*     */   public void setOperateDAO(OperateDAO operateDAO) {
/*  46 */     this.operateDAO = operateDAO;
/*     */   }
/*     */ 
/*     */   public FunctionOperateDAO getFunctionOperateDAO() {
/*  50 */     return this.functionOperateDAO;
/*     */   }
/*     */ 
/*     */   public void setFunctionOperateDAO(FunctionOperateDAO functionOperateDAO) {
/*  54 */     this.functionOperateDAO = functionOperateDAO;
/*     */   }
/*     */ 
/*     */   public List getUsers() {
/*  58 */     return getSqlMapClientTemplate().queryForList("getActivityUsers");
/*     */   }
/*     */ 
/*     */   public List getActivityUsers() {
/*  62 */     return getSqlMapClientTemplate().queryForList("getActivityUsers");
/*     */   }
/*     */ 
/*     */   public List getPageUsersByDeptIds(String deptIds, String isActivity, Page page) {
/*  66 */     Map map = new HashMap();
/*  67 */     map.put("deptIds", deptIds);
/*  68 */     map.put("isActivity", isActivity);
/*  69 */     map.put("pageStartRow", Integer.valueOf(page.getPageStartRow()));
/*  70 */     map.put("pageEndRow", Integer.valueOf(page.getPageEndRow()));
/*  71 */     return getSqlMapClientTemplate().queryForList("getPageUsersByDeptIds", map);
/*     */   }
/*     */   public Integer getPageUsersCountByDeptIds(String deptIds, String isActivity) {
/*  74 */     Map map = new HashMap();
/*  75 */     map.put("deptIds", deptIds);
/*  76 */     map.put("isActivity", isActivity);
/*  77 */     return (Integer)getSqlMapClientTemplate().queryForObject("getPageUsersCountByDeptIds", map);
/*     */   }
/*     */ 
/*     */   public List getPageUsersByRoleId(Integer roleId, Page page) {
/*  81 */     Map map = new HashMap();
/*  82 */     map.put("roleId", roleId);
/*  83 */     map.put("pageStartRow", Integer.valueOf(page.getPageStartRow()));
/*  84 */     map.put("pageEndRow", Integer.valueOf(page.getPageEndRow()));
/*  85 */     return getSqlMapClientTemplate().queryForList("getPageUsersByRoleId", map);
/*     */   }
/*     */   public Integer getPageUsersCountByRoleId(Integer roleId) {
/*  88 */     return (Integer)getSqlMapClientTemplate().queryForObject("getPageUsersCountByRoleId", roleId);
/*     */   }
/*     */ 
/*     */   public List getUsersByDeptId(Integer deptId) {
/*  92 */     return getSqlMapClientTemplate().queryForList("getUsersByDeptId", deptId);
/*     */   }
/*     */ 
/*     */   public String getShareUsersByCustomerId(Integer customerId, Integer mainSalePersonId) {
/*  96 */     if ((customerId == null) || (mainSalePersonId == null)) return null;
/*  97 */     String userNames = "";
/*  98 */     List list = new ArrayList();
/*  99 */     list = getSqlMapClientTemplate().queryForList("getShareUsersByCustomerId", customerId);
/* 100 */     if (list == null) return null;
/* 101 */     for (int i = 0; i < list.size(); i++) {
/* 102 */       Users user = new Users();
/* 103 */       user = (Users)list.get(i);
/* 104 */       if (user.getId().compareTo(mainSalePersonId) != 0) {
/* 105 */         if (i == list.size() - 1)
/* 106 */           userNames = userNames + user.getUserName();
/*     */         else {
/* 108 */           userNames = userNames + user.getUserName() + " , ";
/*     */         }
/*     */       }
/*     */     }
/* 112 */     return userNames;
/*     */   }
/*     */ 
/*     */   public Users getUser(Integer id) {
/* 116 */     if (id == null) return null;
/* 117 */     return (Users)getSqlMapClientTemplate().queryForObject("getUser", id);
/*     */   }
/*     */ 
/*     */   public String getUserNameById(Integer id) {
/* 121 */     if (id == null) return null;
/* 122 */     String userName = "";
/* 123 */     Users user = new Users();
/* 124 */     user = getUser(id);
/* 125 */     if (user == null) return null;
/* 126 */     userName = user.getUserName();
/* 127 */     return userName;
/*     */   }
/*     */ 
/*     */   public Users getUserByUserCode(String userCode) {
/* 131 */     return (Users)getSqlMapClientTemplate().queryForObject("getUserByUserCode", userCode);
/*     */   }
/*     */ 
/*     */   public Users getUserByUserName(String userName) {
/* 135 */     return (Users)getSqlMapClientTemplate().queryForObject("getUserByUserName", userName);
/*     */   }
/*     */ 
/*     */   public Users getUserByDynamic(Users user) {
/* 139 */     return (Users)getSqlMapClientTemplate().queryForObject("getUserByDynamic", user);
/*     */   }
/*     */ 
/*     */   public List getUserActivityByDeptId(Integer deptId) {
/* 143 */     Users user = new Users();
/* 144 */     user.setIsActivity("1");
/* 145 */     user.setDeptId(deptId);
/* 146 */     return getSqlMapClientTemplate().queryForList("getUsersByDynamic", user);
/*     */   }
/*     */ 
/*     */   public List getUsersByDynamic(Users user) {
/* 150 */     return getSqlMapClientTemplate().queryForList("getUsersByDynamic", user);
/*     */   }
/*     */ 
/*     */   public List getUsersByRoleId(Integer roleId) {
/* 154 */     if (roleId == null) return null;
/* 155 */     Users user = new Users();
/* 156 */     user.setRoleId(roleId);
/* 157 */     return getUsersByDynamic(user);
/*     */   }
/*     */ 
/*     */   public String getUserEmailById(Integer id) {
/* 161 */     if (id == null) return null;
/* 162 */     Users user = new Users();
/* 163 */     user = getUser(id);
/* 164 */     if ((user == null) || (StringUtils.isEmpty(user.getEmail()))) return null;
/* 165 */     return user.getEmail();
/*     */   }
/*     */ 
/*     */   public Integer getUserDeptIdById(Integer id) {
/* 169 */     if (id == null) return null;
/* 170 */     Users user = new Users();
/* 171 */     user = getUser(id);
/* 172 */     if ((user == null) || (user.getDeptId() == null)) return null;
/* 173 */     return user.getDeptId();
/*     */   }
/*     */ 
/*     */   public boolean insertUser(Users user) {
/* 177 */     Integer result = (Integer)getSqlMapClientTemplate().insert("insertUser", user);
/* 178 */     return result != null;
/*     */   }
/*     */ 
/*     */   public boolean updateUser(Users user)
/*     */   {
/* 183 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().update("updateUser", user));
/* 184 */     return result != null;
/*     */   }
/*     */ 
/*     */   public boolean updateUserPassword(Integer id, String password)
/*     */   {
/* 189 */     Map map = new HashMap();
/* 190 */     map.put("id", id);
/* 191 */     map.put("password", password);
/* 192 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().update("updateUserPassword", map));
/* 193 */     return result != null;
/*     */   }
/*     */ 
/*     */   public boolean updateUserByDynamic(Users user)
/*     */   {
/* 198 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().update("updateUserByDynamic", user));
/* 199 */     return result != null;
/*     */   }
/*     */ 
/*     */   public boolean updateUserLastLoginDate(Integer userId)
/*     */   {
/* 204 */     if (userId == null) return false;
/* 205 */     Users user = new Users();
/* 206 */     user = getUser(userId);
/* 207 */     if (user == null) return false;
/*     */ 
/* 209 */     Users newUser = new Users();
/* 210 */     newUser.setId(userId);
/* 211 */     newUser.setLastLoginDate(user.getLoginDate());
/*     */ 
/* 213 */     return updateUserByDynamic(newUser);
/*     */   }
/*     */ 
/*     */   public boolean deleteUser(Integer id) {
/* 217 */     Integer result = Integer.valueOf(getSqlMapClientTemplate().delete("deleteUser", id));
/* 218 */     return result != null;
/*     */   }
/*     */ 
/*     */   public List getAuditUsers(Integer userId)
/*     */   {
/* 223 */     List users = new ArrayList();
/*     */ 
/* 225 */     Operate operate = new Operate();
/* 226 */     operate = this.operateDAO.getOperateByCode("isAuditAllInvoice");
/* 227 */     if (operate != null) {
/* 228 */       List functionOperates = new ArrayList();
/* 229 */       functionOperates = this.functionOperateDAO.getFunctionOperatesByOperateId(operate.getId());
/* 230 */       if (functionOperates != null) {
/* 231 */         for (int i = 0; i < functionOperates.size(); i++) {
/* 232 */           FunctionOperate functionOperate = new FunctionOperate();
/* 233 */           functionOperate = (FunctionOperate)functionOperates.get(i);
/* 234 */           if (functionOperate.getRoleId() != null) {
/* 235 */             users.addAll(getUsersByRoleId(functionOperate.getRoleId()));
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 241 */     operate = new Operate();
/* 242 */     operate = this.operateDAO.getOperateByCode("isAuditDeptInvoice");
/* 243 */     if ((operate != null) && (userId != null)) {
/* 244 */       Users user = new Users();
/* 245 */       user = getUser(userId);
/* 246 */       Integer deptId = user.getDeptId();
/*     */ 
/* 248 */       if ((user == null) && (deptId != null)) return users;
/* 249 */       List functionOperates = new ArrayList();
/* 250 */       functionOperates = this.functionOperateDAO.getFunctionOperatesByOperateId(operate.getId());
/* 251 */       if (functionOperates != null) {
/* 252 */         for (int i = 0; i < functionOperates.size(); i++) {
/* 253 */           FunctionOperate functionOperate = new FunctionOperate();
/* 254 */           functionOperate = (FunctionOperate)functionOperates.get(i);
/* 255 */           if (functionOperate.getRoleId() != null) {
/* 256 */             List tUsers = new ArrayList();
/* 257 */             tUsers = getUsersByRoleId(functionOperate.getRoleId());
/* 258 */             if ((tUsers != null) && (tUsers.size() > 0)) {
/* 259 */               for (int j = 0; j < tUsers.size(); j++) {
/* 260 */                 user = new Users();
/* 261 */                 user = (Users)tUsers.get(j);
/* 262 */                 if (user.getDeptId() != null) {
/* 263 */                   String deptIds = this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByDeptId(user.getDeptId());
/* 264 */                   if ((!StringUtils.isEmpty(deptIds)) && (deptIds.indexOf(deptId.toString()) != -1)) {
/* 265 */                     users.add(user);
/*     */                   }
/*     */                 }
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 275 */     return users;
/*     */   }
/*     */ 
/*     */   public List getTopFinishedContractCost(Date startDate, Date endDate) {
/* 279 */     if (startDate == null) return null;
/* 280 */     if (endDate == null) return null;
/* 281 */     Map map = new HashMap();
/* 282 */     map.put("startDate", startDate);
/* 283 */     map.put("endDate", endDate);
/* 284 */     return getSqlMapClientTemplate().queryForList("getTopFinishedContractCost", map);
/*     */   }
/*     */ 
/*     */   public List getTopFinishedBackCost(Date startDate, Date endDate) {
/* 288 */     if (startDate == null) return null;
/* 289 */     if (endDate == null) return null;
/* 290 */     Map map = new HashMap();
/* 291 */     map.put("startDate", startDate);
/* 292 */     map.put("endDate", endDate);
/* 293 */     return getSqlMapClientTemplate().queryForList("getTopFinishedBackCost", map);
/*     */   }
/*     */ 
/*     */   public List getTopFinishedGrossProfit(Date startDate, Date endDate) {
/* 297 */     if (startDate == null) return null;
/* 298 */     if (endDate == null) return null;
/* 299 */     Map map = new HashMap();
/* 300 */     map.put("startDate", startDate);
/* 301 */     map.put("endDate", endDate);
/* 302 */     return getSqlMapClientTemplate().queryForList("getTopFinishedGrossProfit", map);
/*     */   }
/*     */ 
/*     */   public List getTopFinishedHandGrossProfit(Date startDate, Date endDate) {
/* 306 */     if (startDate == null) return null;
/* 307 */     if (endDate == null) return null;
/* 308 */     Map map = new HashMap();
/* 309 */     map.put("startDate", startDate);
/* 310 */     map.put("endDate", endDate);
/* 311 */     return getSqlMapClientTemplate().queryForList("getTopFinishedHandGrossProfit", map);
/*     */   }
/*     */ 
/*     */   public List getTopFinishedGrossBackCost(Date startDate, Date endDate) {
/* 315 */     if (startDate == null) return null;
/* 316 */     if (endDate == null) return null;
/* 317 */     Map map = new HashMap();
/* 318 */     map.put("startDate", startDate);
/* 319 */     map.put("endDate", endDate);
/* 320 */     return getSqlMapClientTemplate().queryForList("getTopFinishedGrossBackCost", map);
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.dao.impl.UserDAOImpl
 * JD-Core Version:    0.6.0
 */